/**
 * 判断指定文件路径的是否为txt格式（通过后缀名判断）的示例程序
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>


int is_format(const char *file_path, const char *file_format)
{
    char *pos = strstr(file_path, file_format);
    if (pos == NULL) {
        return 0;
    }
    return 1;
}

int main()
{
    char *file_path = "/home/martin/workspace/test.txt";
    if (is_format(file_path, "txt")) {
        printf("file %s is txt format\n", file_path);
    }
    else {
        printf("file %s is not txt format\n", file_path);
    }

    return 0;
}

